package com.droowa.model.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.ibatis.session.SqlSessionException;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.droowa.domain.Customer;
import com.droowa.domain.CustomerOut;

@Repository
public class CustomerDAOMybatisImpl implements CustomerDAO {
	
	@Autowired
	private SqlSessionTemplate session;
	
	@Override
	public int insertCustomer(Customer customer) throws SqlSessionException{
		return session.insert(makeSqlId("insertCustomer"),customer);
	}
	
	@Override //고객 객체를 아이디로 찾는다. 로그인때사용
	public Customer getCustomerById(String custId) throws SQLException {
		return session.selectOne(makeSqlId("getCustomerById"), custId);
	}
	
	private String makeSqlId(String custId){
		return "customer.manager."+custId;
	}
	
	@Override
	public int updateCustomer(Customer customer) throws SQLException{
		return session.update(makeSqlId("updateCustomer"), customer);
	}
	
	//회원탈퇴
	@Override
	public int deleteCustomerById(String custId) throws SQLException {
		return session.delete(makeSqlId("deleteCustomerById"),custId) ;
	}
	
	@Override
	public List<Customer> selectCustomerList() throws SQLException{
		return session.selectList(makeSqlId("selectCustomerList"));
	}


	@Override
	public List<Customer> selectCustomerListByName(String name) throws SQLException {
		
		return session.selectList(makeSqlId("selectCustomerListByName"),name);
	}

	@Override
	public List<Customer> selectCustomerListByBirth(String birth) throws SQLException {	
		
		return session.selectList(makeSqlId("selectCustomerListByBirth"),birth);
	}

	@Override
	public List<Customer> selectCustomerListByPhone(String phone) throws SQLException {
	
		return session.selectList(makeSqlId("selectCustomerListByPhone"),phone);
	}

	@Override
	public List<Customer> selectCustomerListByAddress(String address) throws SQLException {
	
		return session.selectList(makeSqlId("selectCustomerListByAddress"),address);
	}

	@Override
	public List<Customer> selectCustomerListByJoinDate(String joinDate)	throws SQLException {
		
		return session.selectList(makeSqlId("selectCustomerListByJoinDate"),joinDate);
	}
	

	//탈퇴회원 테이블
	@Override
	public int insertRemoveCustomer(CustomerOut custOut) throws SQLException {
		return session.insert(makeSqlId("insertRemoveCustomer"), custOut);
	}
	
	//탈퇴회원 ID조회 
	@Override
	public CustomerOut getCustomerOutById(String custId) throws SQLException {
		return session.selectOne(makeSqlId("getCustomerOutById"), custId);
	}
	
	//탈퇴회원 전체조회
	@Override
	public List<CustomerOut> selectCustomerOutList() throws SQLException {
		return session.selectList(makeSqlId("selectCustomerOutList"));
	}

	@Override
	public int deleteCustomerOutById(String custId) throws SQLException {
		return session.delete(makeSqlId("deleteCustomerOutById"), custId);
	}
	
	
	
	
	
}












